package club.lovety.es.client;

import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 这里写代码描述
 * @author smc
 * @date 2018-08-28 21:12
 * @since
 **/
public final class ESClientUtils {

    public static Client getClient(){


        Settings settings = Settings.builder().put("cluster.name", "kubernetes-logging")
                .build();
        TransportClient client =null;
        try{
//            client = new PreBuiltTransportClient(Settings.EMPTY)
//                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
            client = new PreBuiltTransportClient(settings)
                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("10.22.19.6"), 30565));
        }catch (Exception ex){
            ex.printStackTrace();
        }
       return client;
    }

    public static void main(String[] args) {
        Client client = getClient();
        try {
            InetAddress inetAddress = InetAddress.getByName("127.0.0.1");
            System.out.println(1);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        System.out.println(2);
    }
}
